<!DOCTYPE html>
<html lang="zh-cmn-Hans">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>伪代码洗衣机 | hez2010</title>
  
  
  
  <!--link rel="stylesheet" href="//cdn.jsdelivr.net/highlight.js/9.10.0/styles/github-gist.min.css"-->
  
<link rel="stylesheet" href="//cdn.jsdelivr.net/highlight.js/9.10.0/styles/github-gist.min.css">

  
<link rel="stylesheet" href="/css/style.css">

<!-- hexo injector head_end start -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/katex.min.css">

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/hexo-math@4.0.0/dist/style.css">
<!-- hexo injector head_end end --><meta name="generator" content="Hexo 5.1.1"></head>

<body>
<div class="Shell">
    <aside class='SideBar'>
    <section class='avatar' style="background-image: url()">
        <div class='av-pic' style="background-image: url(/assets/avatar.jpg)">
        </div>
    </section>
    <section class='menu'>
        <div>hez2010</div>
        
            <div>软件工程导论</div>
        
        <ul>
          
            <a href="/" class="Btn">
              <li>Home</li>
            </a>  
          
            <a href="/archives/" class="Btn">
              <li>Archive</li>
            </a>  
          
        </ul>
    </section>
    <section class="media">
        
            
                <a target="_blank" rel="noopener" href="https://github.com/hez2010">
                    <img src="/assets/github.svg" />
                </a>
            
        
    </section>
</aside>

    <div class="container">
        <div data-pager-shell>
            <div>
  <article class='ContentView'>
    <header class='PageTitle'>
        <h1>伪代码洗衣机</h1>
    </header>

    <section>
      <h1 id="自顶向下，逐步求精"><a href="#自顶向下，逐步求精" class="headerlink" title="自顶向下，逐步求精"></a>自顶向下，逐步求精</h1><p>“自顶向下”的具体内涵是将复杂、大的问题划分为小问题，找出问题的关键、重点所在，然后用精确的思维定性、定量地去描述问题。而“逐步求精”的具体内涵是是将现实世界的问题经抽象转化为逻辑空间或求解空间的问题。复杂问题经抽象化处理变为相对比较简单的问题。经若干步抽象（精化）处理，最后到求解域中只是比较简单的编程问题。</p>
<h1 id="洗衣过程"><a href="#洗衣过程" class="headerlink" title="洗衣过程"></a>洗衣过程</h1><p>洗衣服的过程分为：</p>
<ul>
<li>注水</li>
<li>浸泡</li>
<li>洗涤</li>
<li>排水</li>
<li>干燥</li>
<li>关机</li>
</ul>
<h1 id="一些函数"><a href="#一些函数" class="headerlink" title="一些函数"></a>一些函数</h1><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs none">water_in_switch(open_close) &#x2F;&#x2F; open 打开上水开关，close关闭 <br>water_out_switch(open_close) &#x2F;&#x2F; open 打开排水开关，close关闭<br>get_water_volume() &#x2F;&#x2F;返回洗衣机内部水的高度<br>motor_run(direction) &#x2F;&#x2F; 电机转动。left左转，right右转，stop停 <br>time_counter() &#x2F;&#x2F; 返回当前时间计数，以秒为单位<br>halt(returncode) &#x2F;&#x2F;停机，success 成功 failure 失败<br></code></pre></td></tr></table></figure>

<a id="more"></a>
<h1 id="注水"><a href="#注水" class="headerlink" title="注水"></a>注水</h1><p>该步骤打开水管进行注水，并反复读取水量直到达到设定水量值为止。</p>
<p>假设用户设置的水量为 <code>volumn_set</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs pdl">CALL motor_run with stop<br>CALL water_out_switch with close<br>CALL water_in_switch with open<br>REPECT<br>    CALL get_water_volume RETURNING volume<br>UNTIL volumn &gt;&#x3D; volumn_set<br>CALL water_in_switch with close<br></code></pre></td></tr></table></figure>

<h1 id="浸泡"><a href="#浸泡" class="headerlink" title="浸泡"></a>浸泡</h1><p>该步骤将衣物和水放在一起浸泡，并监控时间直到达到用户设置的时间为止。</p>
<p>假设用户设置的浸泡时间为 <code>soaking_time</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs pdl">CALL motor_run with stop<br>CALL water_out_switch with close<br>CALL water_in_switch with close<br>REPECT<br>    CALL time_counter RETURNING time<br>UNTIL time &gt;&#x3D; soaking_time<br></code></pre></td></tr></table></figure>

<h1 id="洗涤"><a href="#洗涤" class="headerlink" title="洗涤"></a>洗涤</h1><p>该步骤进行洗涤，启动电机并让其来回左右旋转，同时监测时间，直到达到用户设置的洗涤时间为止。</p>
<p>假设用户设置的洗涤时间为 <code>washing_time</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><code class="hljs pdl">CALL water_out_switch with close<br>CALL water_in_switch with close<br>REPECT<br>    CALL motor_run with right<br>    CALL motor_run with left<br>    CALL time_counter RETURNING time<br>UNTIL time &gt;&#x3D; washing_time<br>CALL motor_run with stop<br></code></pre></td></tr></table></figure>

<h1 id="排水"><a href="#排水" class="headerlink" title="排水"></a>排水</h1><p>该步骤把水放出，只需要打开排水管然后检测水量，直到水量归零为止。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs pdl">CALL water_out_switch with open<br>CALL water_in_switch with close<br>CALL motor_run with stop<br>REPECT<br>    CALL get_water_volume RETURNING volume<br>UNTIL volume &#x3D;&#x3D; 0<br></code></pre></td></tr></table></figure>

<h1 id="干燥"><a href="#干燥" class="headerlink" title="干燥"></a>干燥</h1><p>该步骤进行干燥，让电机往一个方向旋转，以达到甩干的目的，直到达到设置的干燥时间为止。</p>
<p>假设用户设置的干燥时间为 <code>dry_time</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs pdl">CALL water_out_switch with open<br>CALL water_in_switch with close<br>CALL motor_run with right<br>REPECT<br>    CALL time_counter RETURNING time<br>UNTIL time &gt;&#x3D; dry_time<br>CALL motor_run with stop<br></code></pre></td></tr></table></figure>

<h1 id="关机"><a href="#关机" class="headerlink" title="关机"></a>关机</h1><p>该步骤将洗衣机关机。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs pdl">CALL water_out_switch with close<br>CALL water_in_switch with close<br>CALL motor_run with stop<br>CALL halt with success<br></code></pre></td></tr></table></figure>


      

    </section>
    
      <section class='ArticleMeta'>
          <div>
            发布于&nbsp;
            <time datetime="2020-11-07T11:45:19.080Z" itemprop="datePublished">
              2020-11-07
            </time>
          </div>
          
      </section>
    
    
</article>

  
</div>

            <footer>
    <div>© 2021 - Steven He </div>
    <div>
        <span>
            Powered by <a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a>
        </span>
        ,
        <span>
            Theme - <a target="_blank" rel="noopener" href="https://github.com/nameoverflow/hexo-theme-icalm">Icalm</a>
        </span>
    </div>
</footer>

        </div>
    </div>
</div>

<script src="/js/pager/dist/singlepager.js"></script>

<script>
var sp = new Pager('data-pager-shell')

</script>
</body>
</html>